﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Other_Addshowboard : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RECORDID.Text = "";
            String rID = Page.Request["ID"];
            if (rID != null && rID != "")
            {
                EntityOprHelper helper = new EntityOprHelper();
                T_SHOWBOARD add = helper.GetEntityByWhere<T_SHOWBOARD>(" where ID=" + rID + "");
                if (add != null)
                {
                    RECORDID.Text = add.ID.ToString();
                    pName.Text = add.NAME;
                    pImage.Text = add.IMAGE;
                    pURL.Text = add.URL;
                }
            }

        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        //T_SHOWBOARD
        if (pName.Text == "")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('请输入名称')", true);
            return;
        }
        EntityOprHelper helper = new EntityOprHelper();
        if (RECORDID.Text != "")
        {
            T_SHOWBOARD address = new T_SHOWBOARD();
            address.NAME = pName.Text;
            address.IMAGE = pImage.Text;
            address.URL = pURL.Text;

            address.ID = Convert.ToInt32(RECORDID.Text);

            bool b1 = helper.EditEntity<T_SHOWBOARD>(address);
            if (b1)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改成功')", true);
                pName.Text = "";
                pImage.Text = "";
                pURL.Text = "";
                RECORDID.Text = "";
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('修改失败')", true);
            }

            return;
        }



        T_SHOWBOARD add = helper.GetEntityByWhere<T_SHOWBOARD>(" where NAME='" + pName.Text + "'");

        if (add != null)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('该展示已经存在')", true);
            return;
        }

        T_SHOWBOARD _address = new T_SHOWBOARD();
        _address.NAME = pName.Text;
        _address.IMAGE = pImage.Text;
        _address.URL = pURL.Text;
        bool b = helper.AddEntity<T_SHOWBOARD>(_address);
        if (b)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加成功')", true);
            pName.Text = "";
            pImage.Text = "";
            pURL.Text = "";

        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('添加失败')", true);
        }


    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        pImage.Text = shareCode.upFileToServer();
    }
}
